import type { Component } from 'vue'

export interface ICondition {
  key?: string
  value?: string
  operator?: string
}

export interface IConditionGroup extends ICondition {
  relation?: 'and' | 'or'
  children?: IConditionGroup[]
}

export interface Option {
  label: string
  value: string
}

export interface ConditionField {
  key: string
  label: string
  component: Component
  operations?: Option[]
  props?: (value: ICondition) => Record<string, any>
  [key: string]: any
}

//
export const defaultValue: IConditionGroup = {
  relation: 'and',
  children: [{}],
}

/** 默认操作符 */
export const defaultOperations = [
  { label: '等于(=)', value: '=' },
  { label: '不等于(!=)', value: '!=' },
  { label: '大于(>)', value: '>' },
  { label: '大于等于(>=)', value: '>=' },
  { label: '小于(<)', value: '<' },
  { label: '小于等于(<=)', value: '<=' },
  { label: `以...开始(like 's%')`, value: 'likeright' },
  { label: `以...结尾(like '%s')`, value: 'likeleft' },
  { label: `在...中(like '%s%')`, value: 'like' },
  { label: `不以...开始(not like 's%')`, value: 'notlikeright' },
  { label: `不以...结尾(not like '%s')`, value: 'notlikeleft' },
  { label: `不在...中(not like '%s%')`, value: 'notlike' },
  { label: '包含(in)', value: 'in' },
  { label: '不包含(not in)', value: 'not in' },
]

/** 默认关系 */
export const defaultRelations = [
  { label: '且', value: 'and' },
  { label: '或', value: 'or' },
]
